<?php

class PaymentmethodsController extends AppController {

    var $name = 'Paymentmethods';

    function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allowedActions = array('*');
    }

    function index() {
        $this->layout = 'innerhome';
        $this->Paymentmethod->recursive = 0;
        $paymentmethods = $this->Paymentmethod->findAllByUserId($this->Auth->User('id'));
        $this->set(compact('paymentmethods'));
    }

    function backstage_index() {
        $this->layout = 'admin';
        $this->Paymentmethod->recursive = 0;
        $paymentmethods = $this->Paymentmethod->findAllByUserId($this->Auth->User('id'));
        $this->set(compact('paymentmethods'));
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid paymentmethod', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('paymentmethod', $this->Paymentmethod->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->Paymentmethod->create();
            if ($this->Paymentmethod->save($this->data)) {
                $this->Session->setFlash(__('The paymentmethod has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The paymentmethod could not be saved. Please, try again.', true));
            }
        }
    }

    function editsuccess() {
        $this->layout = false;
    }

    function edit($id = null) {
        $this->layout = false;
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid paymentmethod', true));
            //$this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Paymentmethod->save($this->data)) {
                $this->Session->setFlash(__('The payment method has been saved successfully', true));
                $this->render('editsuccess');
            } else {
                $this->Session->setFlash(__('The payment method could not be saved. Please, try again.', true));
            }
        }

        if (empty($this->data)) {
            $this->data = $this->Paymentmethod->find("first",array("conditions"=>array('id'=>$id,'user_id'=>$this->Session->read('Auth.User.id'))));
        }
        if ($id == 2) {
            //$this->render('gcheckoutedit');
        }
    }

    function editsadmin($id = null) {
        $this->layout = false;
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid paymentmethod', true));
        }
        if (!empty($this->data)) {
            if ($this->Paymentmethod->save($this->data)) {
                $this->Session->setFlash(__('The payment method has been saved', true));
            } else {
                $this->Session->setFlash(__('The payment method could not be saved. Please, try again.', true));
            }
        }
        $this->data = $this->Paymentmethod->read(null, $id);
    }

    function gcheckoutedit($id = null) {
        $this->layout = false;
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid paymentmethod', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->Paymentmethod->save($this->data)) {
                $this->redirect(array('action' => 'editsuccess'));
            } else {
                $this->Session->setFlash(__('The payment method could not be saved. Please, try again.', true));
            }
        }

        if (empty($this->data)) {
            $this->data = $this->Paymentmethod->read(null, $id);
        }
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for paymentmethod', true));
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Paymentmethod->delete($id)) {
            $this->Session->setFlash(__('Paymentmethod deleted', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('Paymentmethod was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

    function active($id) {
        $this->layout = "ajax";
        $this->Paymentmethod->id = $id;
        $this->data['Paymentmethod']['status'] = 1;
        $this->Paymentmethod->save($this->data);
        $this->set("id", $id);
    }

    function inactive($id) {
        $this->layout = "ajax";
        $this->Paymentmethod->id = $id;
        $this->data['Paymentmethod']['status'] = 0;
        $this->Paymentmethod->save($this->data);
        $this->set("id", $id);
    }

}
?>